package edu.ptu.acl.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import edu.ptu.acl.filter.AclControlFilter;
import edu.ptu.acl.filter.LoginFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class MyConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Bean
    public OptimisticLockerInterceptor mybatisPlusInterceptor() {
        return new OptimisticLockerInterceptor();
    }

    @Bean
    public FilterRegistrationBean loginFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        filterRegistrationBean.setFilter(new LoginFilter());
        filterRegistrationBean.addUrlPatterns("/*");//配置过滤规则
//        filterRegistrationBean.addInitParameter("name","hahahhhaa");//设置init参数
        filterRegistrationBean.setName("reqResFilter1");//设置过滤器名称
        filterRegistrationBean.setOrder(1);//执行次序

        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean aclControlFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        filterRegistrationBean.setFilter(new AclControlFilter());
        filterRegistrationBean.addUrlPatterns("/*");//配置过滤规则
//        filterRegistrationBean.addInitParameter("name","hahahhhaa");//设置init参数
        filterRegistrationBean.setName("reqResFilter2");//设置过滤器名称
        filterRegistrationBean.setOrder(2);//执行次序

        return filterRegistrationBean;
    }

}
